<template>
  <a-spin :spinning="confirmLoading">
    <a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">


      <a-card size="small" title="用户" :bordered="false"
              :headStyle="{background:'#1890ff',color:'white'}">
        <a-row>
          <a-col :span="6">
            <a-form-item label="用户" v-bind="validateInfos.userId">
              <j-search-select v-model:value="formData.userId" dict="sys_user,realname,id"
                               :disabled="true"/>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="手机号" v-bind="validateInfos.userPhone">
              <a-input v-model:value="formData.userPhone" placeholder="请输入用户手机号"
                       :disabled="true"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
      </a-card>


      <a-card size="small" title="行驶证" :bordered="false"
              :headStyle="{background:'#1890ff',color:'white'}">
        <a-row>
          <a-col :span="6">
            <a-space align="center">
              <a-form-item label="" v-bind="validateInfos.drivingLicense">
                <!--                <j-image-upload :fileMax=1 v-model:value="formData.drivingLicense"
                                                :disabled="true"></j-image-upload>-->
                <Image
                  :width="200"
                  :src="formData.drivingLicense"
                />
              </a-form-item>
              <a-space direction="vertical">
                <a-button :icon="h(SearchOutlined)" :loading="drivingOcrLoading"
                          @click="drivingOcr">
                  OCR识别
                </a-button>
                <a-button v-if="drivingOcrResult" @click="assignDriving">
                  一键赋值
                </a-button>
              </a-space>

            </a-space>

          </a-col>
          <a-col :span="18" v-if="drivingOcrResult">
            <div style=" height: 30vh;overflow: auto; ">
              <CodeEditor v-model:value="drivingOcrResult" mode="application/json"
                          style="width:100%;background: grey"/>

            </div>
          </a-col>


        </a-row>

        <a-row>
          <a-col :span="6">
            <a-form-item label="VIN" v-bind="validateInfos.drivingFVin">
              <a-input v-model:value="formData.drivingFVin" placeholder="请输入车辆识别代号"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item v-bind="validateInfos.drivingFVehicleNo">
              <template #label><span title="主页号牌号码">号牌号码</span></template>
              <a-input v-model:value="formData.drivingFVehicleNo" placeholder="请输入号牌号码"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="发证单位" v-bind="validateInfos.drivingFPubOrg">
              <a-input v-model:value="formData.drivingFPubOrg" placeholder="请输入发证单位"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="发证日期" v-bind="validateInfos.drivingFPubDate">
              <a-input v-model:value="formData.drivingFPubDate" placeholder="请输入发证日期"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>

        </a-row>
        <a-row>
          <a-col :span="6">
            <a-form-item label="品牌型号" v-bind="validateInfos.drivingFBrandModel">
              <a-input v-model:value="formData.drivingFBrandModel" placeholder="请输入品牌型号"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="所有人" v-bind="validateInfos.drivingFAny">
              <a-input v-model:value="formData.drivingFAny" placeholder="请输入所有人"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="使用性质" v-bind="validateInfos.drivingFUseProperty">
              <a-input v-model:value="formData.drivingFUseProperty" placeholder="请输入使用性质"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="发动机号码" v-bind="validateInfos.drivingFEngineNo">
              <a-input v-model:value="formData.drivingFEngineNo" placeholder="请输入发动机号码"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>

          <a-col :span="6">
            <a-form-item label="住址" v-bind="validateInfos.drivingFAddr">
              <a-input v-model:value="formData.drivingFAddr" placeholder="请输入住址"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>

          <a-col :span="6">
            <a-form-item label="注册日期" v-bind="validateInfos.drivingFRegDate">
              <a-input v-model:value="formData.drivingFRegDate" placeholder="请输入注册日期"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="检验记录" v-bind="validateInfos.drivingBCheckRecord">
              <a-input v-model:value="formData.drivingBCheckRecord" placeholder="请输入检验记录"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="核定载质量" v-bind="validateInfos.drivingBVgwr">
              <a-input v-model:value="formData.drivingBVgwr" placeholder="请输入核定载质量"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6">
            <a-form-item label="整备质量" v-bind="validateInfos.drivingBCurbWeight">
              <a-input v-model:value="formData.drivingBCurbWeight" placeholder="请输入整备质量"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="外廓尺寸" v-bind="validateInfos.drivingBLwh">
              <a-input v-model:value="formData.drivingBLwh" placeholder="请输入外廓尺寸"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label=" 核定载人数" v-bind="validateInfos.drivingBPax">
              <a-input v-model:value="formData.drivingBPax" placeholder="请输入 核定载人数"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="总质量" v-bind="validateInfos.drivingBGvs">
              <a-input v-model:value="formData.drivingBGvs" placeholder="请输入总质量"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6">
            <a-form-item label="燃油类型" v-bind="validateInfos.drivingBFuelType">
              <a-input v-model:value="formData.drivingBFuelType" placeholder="请输入燃油类型"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="准牵引总质量" v-bind="validateInfos.drivingBGcwr">
              <a-input v-model:value="formData.drivingBGcwr" placeholder="请输入准牵引总质量"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="备注" v-bind="validateInfos.drivingBRemark">
              <a-input v-model:value="formData.drivingBRemark" placeholder="请输入备注"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="档案编号" v-bind="validateInfos.drivingBDocNo">
              <a-input v-model:value="formData.drivingBDocNo" placeholder="请输入档案编号"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6">
            <a-form-item label="号牌号码" v-bind="validateInfos.drivingBVehicleNo">
              <template #label><span title="副页号牌号码">号牌号码</span></template>
              <a-input v-model:value="formData.drivingBVehicleNo" placeholder="请输入号牌号码"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="证芯编号" v-bind="validateInfos.drivingBCcn">
              <a-input v-model:value="formData.drivingBCcn" placeholder="请输入证芯编号"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
      </a-card>


      <a-card size="small" title="道路运输证" :bordered="false"
              :headStyle="{background:'#1890ff',color:'white'}">

<!--        <a-row>
          <a-col :span="6">
            <a-form-item label="道路运输证" v-bind="validateInfos.roadTransportCertificate">
              <j-image-upload :fileMax=1 v-model:value="formData.roadTransportCertificate"
                              :disabled="disabled"></j-image-upload>
            </a-form-item>

          </a-col>
        </a-row>-->
        <a-row>
          <a-col :span="6">
            <a-space align="center">
              <a-form-item label="" v-bind="validateInfos.roadTransportCertificate">
                <!--                <j-image-upload :fileMax=1 v-model:value="formData.drivingLicense"
                                                :disabled="true"></j-image-upload>-->
                <Image
                  :width="200"
                  :src="formData.roadTransportCertificate"
                />
              </a-form-item>
              <a-space direction="vertical">
                <a-button :icon="h(SearchOutlined)" :loading="roadOcrLoading"
                          @click="roadOcr">
                  OCR识别
                </a-button>
                <a-button v-if="roadOcrResult" @click="assignRoad">
                  一键赋值
                </a-button>
              </a-space>

            </a-space>

          </a-col>
          <a-col :span="18" v-if="roadOcrResult">
            <div style=" height: 30vh;overflow: auto; ">
              <CodeEditor v-model:value="roadOcrResult" mode="application/json"
                          style="width:100%;background: grey"/>

            </div>
          </a-col>


        </a-row>
        <a-row>

          <a-col :span="6">
            <a-form-item label="道路运输证号" v-bind="validateInfos.roadNo">
              <a-input v-model:value="formData.roadNo" placeholder="请输入道路运输证号"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="车牌号码" v-bind="validateInfos.roadVehicleNo">
              <a-input v-model:value="formData.roadVehicleNo" placeholder="请输入车牌号码"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="经营许可证号" v-bind="validateInfos.roadBusiPermitNo">
              <a-input v-model:value="formData.roadBusiPermitNo" placeholder="请输入经营许可证号"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>

          <a-col :span="6">
            <a-form-item label="经营范围" v-bind="validateInfos.roadBusiRange">
              <a-input v-model:value="formData.roadBusiRange" placeholder="请输入经营范围"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="6">
            <a-form-item label="车辆毫米_高" v-bind="validateInfos.roadVehicleMmHeight">
              <a-input v-model:value="formData.roadVehicleMmHeight" placeholder="请输入车辆毫米_高"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="车辆毫米_宽" v-bind="validateInfos.roadVehicleMmWeight">
              <a-input v-model:value="formData.roadVehicleMmWeight" placeholder="请输入车辆毫米_宽"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="车辆毫米_长" v-bind="validateInfos.roadVehicleMmLong">
              <a-input v-model:value="formData.roadVehicleMmLong" placeholder="请输入车辆毫米_长"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="发证日期" v-bind="validateInfos.roadPubDate">
              <a-input v-model:value="formData.roadPubDate" placeholder="请输入发证日期"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="6">
            <a-form-item label="车辆类型" v-bind="validateInfos.roadVehicleType">
              <a-input v-model:value="formData.roadVehicleType" placeholder="请输入车辆类型"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="吨座位" v-bind="validateInfos.roadTon">
              <a-input v-model:value="formData.roadTon" placeholder="请输入吨座位"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="备注" v-bind="validateInfos.roadRemark">
              <a-input v-model:value="formData.roadRemark" placeholder="请输入备注"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>

          <a-col :span="6">
            <a-form-item label="经济类型" v-bind="validateInfos.roadEconType">
              <a-input v-model:value="formData.roadEconType" placeholder="请输入经济类型"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>


        </a-row>

        <a-row>
          <a-col :span="6">
            <a-form-item label="地址" v-bind="validateInfos.roadAddr">
              <a-input v-model:value="formData.roadAddr" placeholder="请输入地址"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="业户名称" v-bind="validateInfos.roadUserName">
              <a-input v-model:value="formData.roadUserName" placeholder="请输入业户名称"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="初领日期" v-bind="validateInfos.roadFirstDate">
              <a-input v-model:value="formData.roadFirstDate" placeholder="请输入初领日期"
                       :disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
      </a-card>


      <a-card size="small" title="">
        <a-row>
          <a-col :span="12">
            <a-form-item label="车辆状态" v-bind="validateInfos.vehicleStatus">
              <a-radio-group v-model:value="formData.vehicleStatus" :disabled="disabled">
                <a-radio value="3">通过</a-radio>
                <a-radio value="2">驳回</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
          <a-col v-if="formData.vehicleStatus == 2" :span="12">
            <a-form-item label="驳回原因" v-bind="validateInfos.refuseReason">
              <a-textarea :disabled="disabled" v-model:value="formData.refuseReason"
                          placeholder="请输入驳回原因"></a-textarea>
            </a-form-item>
          </a-col>
        </a-row>

      </a-card>

    </a-form>
  </a-spin>
</template>

<script lang="ts" setup>
import {ref, reactive, defineExpose, nextTick, defineProps, computed, onMounted} from 'vue';
import {defHttp} from '/@/utils/http/axios';
import {useMessage} from '/@/hooks/web/useMessage';
import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
import JSearchSelect from '/@/components/Form/src/jeecg/components/JSearchSelect.vue';
import JImageUpload from '/@/components/Form/src/jeecg/components/JImageUpload.vue';
import {getValueType} from '/@/utils';
import {roadTransportCertificate, saveOrUpdate, vehicleLicenseUrl} from '../WlhyVehicle.api';
import {Form} from 'ant-design-vue';
import {h} from 'vue';
import {SearchOutlined} from '@ant-design/icons-vue';
import {Image} from "ant-design-vue";
import {CodeEditor} from "@/components/CodeEditor";

const drivingOcrLoading = ref(false);
const drivingOcrResult = ref("");
const drivingOcrResultObj = reactive({});

const roadOcrLoading = ref(false);
const roadOcrResult = ref("");
const roadOcrResultObj = reactive({});

const props = defineProps({
  formDisabled: {type: Boolean, default: false},
  formData: {
    type: Object, default: () => {
    }
  },
  formBpm: {type: Boolean, default: true}
});
const formRef = ref();
const useForm = Form.useForm;
const emit = defineEmits(['register', 'ok']);
const formData = reactive<Record<string, any>>({
  id: '',
  userId: '',
  userPhone: '',
  drivingLicense: '',
  drivingFVin: '',
  drivingFAddr: '',
  drivingFPubDate: '',
  drivingFPubOrg: '',
  drivingFBrandModel: '',
  drivingFAny: '',
  drivingFUseProperty: '',
  drivingFEngineNo: '',
  drivingFVehicleNo: '',
  drivingFRegDate: '',
  drivingBCheckRecord: '',
  drivingBVgwr: '',
  drivingBCurbWeight: '',
  drivingBLwh: '',
  drivingBPax: '',
  drivingBGvs: '',
  drivingBFuelType: '',
  drivingBGcwr: '',
  drivingBRemark: '',
  drivingBDocNo: '',
  drivingBVehicleNo: '',
  drivingBCcn: '',
  roadTransportCertificate: '',
  roadNo: '',
  roadVehicleNo: '',
  roadEconType: '',
  roadBusiRange: '',
  roadVehicleType: '',
  roadTon: '',
  roadRemark: '',
  roadBusiPermitNo: '',
  roadVehicleMmHeight: '',
  roadVehicleMmWeight: '',
  roadVehicleMmLong: '',
  roadPubDate: '',
  roadAddr: '',
  roadUserName: '',
  roadFirstDate: '',
  vehicleStatus: '',
  status: '',
  refuseReason: '',
});
const {createMessage} = useMessage();
const labelCol = ref<any>({xs: {span: 24}, sm: {span: 5}});
const wrapperCol = ref<any>({xs: {span: 24}, sm: {span: 16}});
const confirmLoading = ref<boolean>(false);
//表单验证
const validatorRules = {
  userId: [{required: true, message: '请输入用户!'},],
  userPhone: [{required: true, message: '请输入用户手机号!'},],
  drivingLicense: [{required: true, message: '请输入行驶证!'},],
  drivingFVin: [{required: true, message: '请输入车辆识别代号!'},],
  drivingFVehicleNo: [{required: true, message: '请输入主页号牌号码!'},],
  drivingFPubOrg: [{required: true, message: '请输入发证单位!'},],
  roadTransportCertificate: [{required: true, message: '请输入道路运输证!'},],
  roadNo: [{required: true, message: '请输入道路运输证号!'},],
  roadVehicleNo: [{required: true, message: '请输入车牌号码!'},],
  roadBusiPermitNo: [{required: true, message: '请输入经营许可证!'},],
  roadBusiRange: [{required: true, message: '请输入经营范围!'},],
};
const {
  resetFields,
  validate,
  validateInfos
} = useForm(formData, validatorRules, {immediate: false});

// 表单禁用
const disabled = computed(() => {
  if (props.formBpm === true) {
    if (props.formData.disabled === false) {
      return false;
    } else {
      return true;
    }
  }
  return props.formDisabled;
});
/**
 * 行驶识别
 */
const drivingOcr = () => {
  if (!formData.drivingLicense) {
    createMessage.warning("请上传行驶证")
    return;
  }
  drivingOcrLoading.value = true;
  vehicleLicenseUrl(formData.drivingLicense).then((res) => {
    for (let key in drivingOcrResultObj) {
      if (drivingOcrResultObj.hasOwnProperty(key)) {
        delete drivingOcrResultObj[key];
      }
    }
    Object.assign(drivingOcrResultObj, res)
    drivingOcrResult.value = JSON.stringify(res);
  })
    .finally(() => {
      drivingOcrLoading.value = false;
    });
}
/**
 * 道路运输识别
 */

const roadOcr = () => {
  if (!formData.roadTransportCertificate) {
    createMessage.warning("请上传道路运输证")
    return;
  }
  roadOcrLoading.value = true;
  roadTransportCertificate(formData.roadTransportCertificate).then((res) => {
    for (let key in roadOcrResultObj) {
      if (roadOcrResultObj.hasOwnProperty(key)) {
        delete roadOcrResultObj[key];
      }
    }
    debugger
    Object.assign(roadOcrResultObj, res)
    roadOcrResult.value = JSON.stringify(res);
  })
    .finally(() => {
      roadOcrLoading.value = false;
    });
}


/**
 * 行驶证赋值
 */
const assignDriving = () => {
  const drivingFront = drivingOcrResultObj["行驶证主页"];
  const drivingBack = drivingOcrResultObj["行驶证副页"];
  formData.drivingFVin = drivingFront["车辆识别代号"]["words"]||'';
  formData.drivingFAddr = drivingFront["住址"]["words"]||'';
  formData.drivingFAny = drivingFront["所有人"]["words"]||'';
  formData.drivingFBrandModel = drivingFront["品牌型号"]["words"]||'';
  formData.drivingFEngineNo = drivingFront["发动机号码"]["words"]||'';
  formData.drivingFPubDate = drivingFront["发证日期"]["words"]||'';
  formData.drivingFPubOrg = drivingFront["发证单位"]["words"]||'';
  formData.drivingFRegDate = drivingFront["注册日期"]["words"]||'';
  formData.drivingFUseProperty = drivingFront["使用性质"]["words"]||'';
  formData.drivingFVehicleNo = drivingFront["号牌号码"]["words"]||'';

    formData.drivingBCcn = drivingBack["证芯编号"]["words"]||'';
    formData.drivingBCheckRecord = drivingBack["检验记录"]["words"]||'';
    formData.drivingBCurbWeight = drivingBack["整备质量"]["words"]||'';
    formData.drivingBDocNo = drivingBack["档案编号"]["words"]||'';
    formData.drivingBFuelType = drivingBack["燃油类型"]["words"]||'';
    formData.drivingBGcwr = drivingBack["准牵引总质量"]["words"]||'';
    formData.drivingBGvs = drivingBack["总质量"]["words"]||'';
    formData.drivingBLwh = drivingBack["外廓尺寸"]["words"]||'';
    formData.drivingBPax = drivingBack["核定载人数"]["words"]||'';
    formData.drivingBRemark = drivingBack["备注"]["words"]||'';
    formData.drivingBVehicleNo	 = drivingBack["号牌号码"]["words"]||'';
    formData.drivingBVgwr = drivingBack["核定载质量"]["words"]||'';
}

/**
 * 行驶证赋值
 */
const assignRoad = () => {

  formData.roadAddr = roadOcrResultObj["地址"][0]["word"]||'';
  formData.roadBusiPermitNo = roadOcrResultObj["经营许可证"][0]["word"]||'';
  formData.roadBusiRange = roadOcrResultObj["经营范围"][0]["word"]||'';
  formData.roadEconType = roadOcrResultObj["经济类型"][0]["word"]||'';
  formData.roadFirstDate = roadOcrResultObj["初领日期"][0]["word"]||'';
  formData.roadNo = roadOcrResultObj["道路运输证号"][0]["word"]||'';
  formData.roadPubDate = roadOcrResultObj["发证日期"][0]["word"]||'';
  formData.roadRemark = roadOcrResultObj["备注"][0]["word"]||'';
  formData.roadTon = roadOcrResultObj["吨座位"][0]["word"]||'';
  formData.roadUserName = roadOcrResultObj["业户名称"][0]["word"]||'';
  formData.roadVehicleMmHeight = roadOcrResultObj["车辆毫米_高"][0]["word"]||'';
  formData.roadVehicleMmLong = roadOcrResultObj["车辆毫米_长"][0]["word"]||'';
  formData.roadVehicleMmWeight = roadOcrResultObj["车辆毫米_宽"][0]["word"]||'';
  formData.roadVehicleNo = roadOcrResultObj["车辆号牌"][0]["word"]||'';
  formData.roadVehicleType = roadOcrResultObj["车辆类型"][0]["word"]||'';

}

/**
 * 新增
 */
function add() {
  edit({});
}

/**
 * 编辑
 */
function edit(record) {
  drivingOcrResult.value = "";
  roadOcrResult.value = "";
  nextTick(() => {
    resetFields();
    const tmpData = {};
    Object.keys(formData).forEach((key) => {
      if (record.hasOwnProperty(key)) {
        tmpData[key] = record[key]
      }
    })
    //赋值
    Object.assign(formData, tmpData);
  });
}

/**
 * 提交数据
 */
async function submitForm() {
  // 触发表单验证
  await validate();
  confirmLoading.value = true;
  const isUpdate = ref<boolean>(false);
  //时间格式化
  let model = formData;
  if (model.id) {
    isUpdate.value = true;
  }
  //循环数据
  for (let data in model) {
    //如果该数据是数组并且是字符串类型
    if (model[data] instanceof Array) {
      let valueType = getValueType(formRef.value.getProps, data);
      //如果是字符串类型的需要变成以逗号分割的字符串
      if (valueType === 'string') {
        model[data] = model[data].join(',');
      }
    }
  }
  await saveOrUpdate(model, isUpdate.value)
    .then((res) => {
      if (res.success) {
        createMessage.success(res.message);
        emit('ok');
      } else {
        createMessage.warning(res.message);
      }
    })
    .finally(() => {
      confirmLoading.value = false;
    });
}


defineExpose({
  add,
  edit,
  submitForm,
});
</script>

<style lang="less" scoped>
.antd-modal-form {
  height: calc(90vh) !important;
  overflow-y: auto;
  padding: 14px;
}
</style>
